package org.tokaf.datasearcher;

import org.openrdf.sesame.Sesame;
import org.openrdf.sesame.repository.SesameService;
import org.openrdf.sesame.repository.local.LocalService;

/**
 * <p>Uses Sesame in repository mode.</p> <p>Copyright (c) 2006</p>
 * @author Alan Eckhardt
 * @version 1.0
 */
public class SesameRepositorySearcher extends SesameSearcher {

	public SesameRepositorySearcher() {
		userName = "testuser";
		password = "opensesame";
	}

	public Object clone() {
		SesameRepositorySearcher newInstance = new SesameRepositorySearcher();
		newInstance.initSource(this);
		newInstance.results = this.results;
		newInstance.columnCount = this.columnCount;
		newInstance.index = this.index;
		newInstance.searchIndex = this.searchIndex;
		newInstance.query = this.query;
		return newInstance;
	}

	public int initSource(String db) {
		return initSource(db, null);
	}

	public int initSource(String Repos, java.net.URL sesameServerURL) {

		long startTime = System.nanoTime();
		if (Repos == null)
			Repos = "mem-rdf-db";
		try {
			if (sesameServerURL == null)
				sesameServerURL = new java.net.URL(
						"http://localhost:8080/sesame/");
			SesameService service = Sesame.getService(sesameServerURL);
			LocalService b = Sesame.getService();
			boolean inferencing = true;
			b.createRepository("myRep", inferencing);
			service.login(userName, password);
			myRepository = service.getRepository(Repos);

		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		initSourceTime = System.nanoTime() - startTime;
		return 1;

	}

}
